<?php

/**
 * MVM_MALL 网上商店系统 共同引导文件
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-03-01 $
 * $Id: common.inc.php  www.mvmmall.com$
 * ---------------------------------------------
*/
error_reporting(E_ERROR | E_PARSE);
set_time_limit(0);
set_magic_quotes_runtime(0);
$t_arr        = explode(' ',microtime());
$mvmmal_start = $t_arr[0] + $t_arr[1];

define('MVMMALL', TRUE);
define('MVMMALL_ROOT', substr(dirname(__FILE__), 0, -7));
!defined('MVMMALL_SCR') && define('MVMMALL_SCR','');
define('MVMMALL_CACHE', MVMMALL_ROOT.'data/cache/');
DIRECTORY_SEPARATOR == '\\'?@ini_set('include_path', '.;' . MVMMALL_ROOT):@ini_set('include_path', '.:' . MVMMALL_ROOT);
PHP_VERSION > '5.1' && date_default_timezone_set('Etc/GMT+0');
session_cache_limiter('private, must-revalidate'); 
@ini_set('session.auto_start',0); //自动启动关闭
if(PHP_VERSION < '4.1.0') {
	$_GET         = &$HTTP_GET_VARS;
	$_POST        = &$HTTP_POST_VARS;
	$_COOKIE      = &$HTTP_COOKIE_VARS;
	$_SERVER      = &$HTTP_SERVER_VARS;
	$_ENV         = &$HTTP_ENV_VARS;
	$_FILES       = &$HTTP_POST_FILES;
}
require_once dirname(__file__).'/global.func.php';
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());//导致双层转义
if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {
	exit('Access Error');
}
foreach(array('_COOKIE', '_POST', '_GET') as $req) {
	foreach($$req as $_key => $_value) {
		$_key{0} != '_' && $$_key = daddslashes($_value);
	}
}
(!MAGIC_QUOTES_GPC)  && $_FILES = daddslashes($_FILES);
$db_charse = $session_lifetime = $con_db_host = $database = $con_db_id = $con_db_pass = $con_db_name = $tablepre = $db = $m_check_cart = false;
$m_class_array  = $char_key = $m_supply_array = $status_arr = $m_order_type_array  = $lang = array();

!$_SERVER['PHP_SELF'] && $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
$REQUEST_URI       = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
$self_temp         = strrpos($_SERVER['PHP_SELF'],'/');
$basename          = substr($_SERVER['PHP_SELF'],$self_temp+1);
define('MVMMALL_DIR','http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,$self_temp));//程序路径
$forward           = settype($referer,'string')?$referer:$_SERVER['HTTP_REFERER'];
$char_key          = array("\\",'&',' ',"'",'"','/','*',',','<','>',"\r","\t","\n",'#','%','?');
$m_now_time        = time();
$m_now_counter     = date('Ymd',$m_now_time);
$m_now_month       = date('Ym',$m_now_time);
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
	$m_user_ip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
	$m_user_ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
	$m_user_ip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
	$m_user_ip = $_SERVER['REMOTE_ADDR'];
}
preg_match("/[\d\.]{7,15}/", $m_user_ip, $ipmat);
$m_user_ip = $ipmat[0] ? $ipmat[0] : 'unknown';
unset($ipmat);
//用户配置文件处理
require_once MVMMALL_ROOT.'./config/config_db.php';
require_once MVMMALL_ROOT.'./include/mysql_class.php';
$db = new dbmysql();
$db->dbconn($con_db_host,$con_db_id,$con_db_pass,$con_db_name);
unset($con_db_id,$con_db_pass,$db_settings);

//缓存类
require_once MVMMALL_ROOT.'./include/cache.class.php';
$cache = new cache($db,$tablepre);        
//系统配置文件
$settings  = $cache->get_cache('cfg');
@extract($settings,EXTR_OVERWRITE);
unset($settings);
$mm_limit_list<0 && $mm_limit_list = 10;
$m_class_array = $cache->get_cache('grade');
$mm_obstart == 1  && function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') :ob_start();
$imgpath                = "images/$mm_skin_name";
$m_supply_array         = array('','','','不良供应公司','供应公司','不良入店公司','入店公司');
$status_arr             = array("","最新商品","推荐商品","热门商品");
$m_order_type_array     = array("一般定单","团购定单","拍卖定单","团购临时定单");

//执行session类
require_once MVMMALL_ROOT.'./include/session.class.php';
!file_exists($mm_session_dir) ? $session_save_dir = MVMMALL_ROOT.'./data/session' : $session_save_dir = $mm_session_dir; //存取的目录
!$session_lifetime && $session_lifetime = get_cfg_var('session.gc_maxlifetime'); //SESSION的存活期
PHPVERSION()<'5'?mvm_session::handler():eval(mvm_session::handler());
session_start();
if (isset($_SESSION['user']['mvm_sess_id'])) {
	$m_check_id      = $_SESSION['user']['mvm_sess_id'];
	$m_check_uid     = $_SESSION['user']['mvm_sess_uid'];
	$m_check_name    = $_SESSION['user']['mvm_sess_name'];
	$m_check_rank    = $_SESSION['user']['mvm_sess_rank'];
	$m_check_email   = $_SESSION['user']['mvm_sess_email'];
	$m_check_point   = number_format($_SESSION['user']['mvm_sess_point'],0);
	$m_check_money   = currency($_SESSION['user']['mvm_sess_money']);
	$mm_adminid      = $_SESSION['user']['mvm_adminid'];
	$mm_group_id     = $_SESSION['user']['mvm_group_id'];
	$mvm_rank_list   = $_SESSION['user']['mvm_rank_list'];
}else {
	$m_check_id  = $m_check_uid = $m_check_name = $m_check_rank = $m_check_email = $m_check_point = $m_check_money = $mm_adminid = false;
}
$m_check_cart = $_COOKIE['mvmall_cart'] ? dhtmlchars($_COOKIE['mvmall_cart']) : setcookie('mvmall_cart',$m_now_time.'_'.rand(10000,99999), time() + $m_now_time - (60 * 60 * $mm_stock_time));
if (!in_array(MVMMALL_SCR,array('admincp','rss'))) {
	if (file_exists(MVMMALL_ROOT.'./language/'.$mm_lang.'/lang_'.$mm_lang.'.php') && file_exists(MVMMALL_ROOT.'./language/'.$mm_lang.'/lang_common.php')) {
		include MVMMALL_ROOT.'./language/'.$mm_lang.'/lang_'.$mm_lang.'.php';
		include MVMMALL_ROOT.'./language/'.$mm_lang.'/lang_common.php';
	} else {
		exit('Language Error!');
	}
}
$mm_language_method = $mm_lang.'/lang_'.$mm_lang;
$m_order_array  = $lang['order_status'];

//关闭登陆
if ($mm_close==0 && $mm_adminid!=1){
    if($setp==1 && $_POST){
        //登陆验证码判断
        if($mm_login_code==1){
            require_once MVMMALL_ROOT.'./include/captcha.class.php';
            $Captcha= new  Captcha();
            !$Captcha->CheckCode($code) && show_msg('code_wrong');
        }
        !$login_id   && show_msg('intput_member');
        !$login_pass &&  show_msg('password_require');
        $login_pass  = md5(dhtmlchars($login_pass));
        $login_id    = dhtmlchars($login_id);
        require_once MVMMALL_ROOT.'./include/passport.inc.php';
    }else {
        require_once MVMMALL_ROOT.'./include/captcha.class.php';
        require_once MVMMALL_ROOT.'header.php';
        $Captcha = new  Captcha();
        $Captcha->CreateCheckCode();
        $captcha = $_SESSION['mm_capcha'];
        include template('login');
        footer();
    }
    exit;
}
//end

//推广
if($mm_extend == '1' && isset($_GET['userid']) && !$_COOKIE['userid']){
	$userid  = intval($_GET['userid']);
	$id_list = $db->get_one("SELECT member_id,uid FROM `{$tablepre}member_table` WHERE uid = '$userid'");
	$id_list['uid']==$userid && setcookie('userid',$id_list['member_id'],time()+86400);
	unset($id_list);
}

